<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <span>你的所在地区为:
        <h1></h1>
        <h2></h2>
    </span>
    <span>你的网络运用商是:<h3></h3></span>
    <div id="city"></div>
</body>
</html>
<script>
    //1.需要创建 xmlhttp
let xhr = new XMLHttpRequest()
//console.log(xhr.onreadystatechange);
//console.log(xhr.readyState);
//console.log(xhr.responseText);
//console.log(xhr.status);
//console.log(xhr.statusText);
//2. 建立链接
xhr.open('get','https://tenapi.cn/v2/getip',true)
//3.发送请求
xhr.send(null)
//4.接收数据
xhr.onreadystatechange = function(){
    if(xhr.readyState === 4 && xhr.status === 200 ){
        console.log(JSON.parse(xhr.responseText))
            document.querySelector("h1").innerText = JSON.parse(xhr.responseText).data.country
            document.querySelector("h2").innerText = JSON.parse(xhr.responseText).data.province
            document.querySelector("h3").innerText = JSON.parse(xhr.responseText).data.isp
            document.querySelector("city").innerText = JSON.parse(xhr.responseText).data.city
    }
}

</script>